package com.example.dtos;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.example.exceptions.AtLeast1ItemException;
import com.example.exceptions.MissingAttributesException;
import com.example.models.Cart;
import com.example.models.ItemToPurchase;
import com.example.models.Product;

public class ItemToPurchaseDTO implements Comparable<ItemToPurchaseDTO>{
	private String id;
	@NotNull(message="product_id is mandatory")
	@NotBlank(message="product_id cant be blank")
	private String product_id; //THIS IS WITH MONGODB
//	private Long id,product_id;
	@Min(value=1 , message="product_id cant be blank")
	private int quantity;
	
	public ItemToPurchaseDTO(){}
	
	public ItemToPurchaseDTO(String id, int quantity, String product_id) {
//	public ItemToPurchaseDTO(Long id, int quantity, Long product_id) {
		super();
		this.id = id;
		this.quantity = quantity;
		this.product_id = product_id;
	}
	 
	public ItemToPurchaseDTO(String id, String product_id, int quantity) {
		super();
		this.id = id;
		this.product_id = product_id;
		this.quantity = quantity;
	}
	
	 public static void checkFields(ItemToPurchaseDTO itemDTO){
		 if (itemDTO.getQuantity() <= 0) throw new AtLeast1ItemException();
		 if (itemDTO.getProduct_id()==null) throw new MissingAttributesException();
	}

	 
//	 public Long getId() {
//		return id;
//	}
//
//	public void setId(Long id) {
//		this.id = id;
//	}

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

//	public Long getProduct_id() {
//		return product_id;
//	}
//
//	public void setProduct_id(Long product_id) {
//		this.product_id = product_id;
//	}

	public String getProduct_id() {
		return product_id;
	}

	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}

	@Override
	public int compareTo(ItemToPurchaseDTO arg0) {
		// TODO Auto-generated method stub
		return this.getId().compareTo(arg0.getId());
	}
	
	
}